﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LapTop
{
    class Program
    {
        static void Main(string[] args)
        {
            //(Список ноутбуков должен заполняться пользователем из консоли)

            List<eachLaptop> allLaptops = new List<eachLaptop>();

            string listAddChoice = "n";

            do
            {
                Console.Clear();
                eachLaptop newLaptop = new eachLaptop();
                newLaptop.AddNewLaptop();
                allLaptops.Add(newLaptop);
                Console.WriteLine("Add another Laptop into the list ? y/n");
                listAddChoice = Console.ReadLine().ToLower();

            } while (listAddChoice == "y");

            Console.Clear();
            PrintListOfLaptops(allLaptops);

            Console.WriteLine("Press any key to continue .\t.\t.");
            Console.ReadKey();


            string userMenuChoice = "n";
            do
            {
                Console.Clear();
                Console.Write("Choose the task 1/2/3\n" +
                    "1 - Layout laptops list\n" +
                    "2 - Select by user choice\n" +
                    "3 - Add laptop to shop list\n");
                string choiceTask = Console.ReadLine();
                switch (choiceTask)
                {
                    case "1":
                        Console.Clear();
                        Console.WriteLine("Layout laptops list");
                        PrintListOfLaptops(allLaptops);
                        break;
                    case "2":
                        Console.Clear();
                        Console.WriteLine("Select by user choice");
                        PrintSelectedByUser(allLaptops);
                        break;
                    case "3":
                        Console.Clear();
                        Console.WriteLine("Add laptop to shop list");
                        LaptopAddToList(allLaptops);
                        break;
                }
                Console.WriteLine("do another task y/n");
                userMenuChoice = Console.ReadLine().ToLower();
                Console.Clear();

            } while (userMenuChoice == "y");

        }
        //Если такого ноута нет -вывести на экран соответствуещее сообщение. 

        static List<eachLaptop> LaptopAddToList(List<eachLaptop> allLaptops)
        {
            string listAddChoice = "n";

            do
            {
                Console.Clear();
                eachLaptop newLaptop = new eachLaptop();
                newLaptop.AddNewLaptop();
                allLaptops.Add(newLaptop);
                Console.WriteLine("Add another laptop the list y/n ? ");
                listAddChoice = Console.ReadLine().ToLower();

            } while (listAddChoice == "y");

            Console.Clear();
            PrintListOfLaptops(allLaptops);
            Console.WriteLine();
            Console.WriteLine("Press any key to continue .\t.\t.");
            Console.ReadKey();

            return allLaptops;
        }

        static void PrintListOfLaptops(List<eachLaptop> allLaptops)
        {
            Console.WriteLine("All laptops available in shop:\n");
            foreach (var laptop in allLaptops)
            {
                laptop.PrintLaptopInfo();
            }

        }


        //Написать программу в которой пользователь сможет подобрать себе ноутбук по введенным критериям отбора.

        static void PrintSelectedByUser(List<eachLaptop> allLaptops)
        {
            Console.Write("Enter laptop vendor name: ");
            string userVendorName = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Enter laptop vendor Country: ");
            string userVendorCountry = Console.ReadLine();
            Console.WriteLine();
            Console.Write("Enter laptop screen size: ");
            int userScreenSize = Int32.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.Write("Enter laptop price: ");
            int userLaptopRAM = Int32.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.Write("Enter laptop price: ");
            double userLaptopPrice = Double.Parse(Console.ReadLine());

            foreach (var laptop in allLaptops)
            {
                if ((laptop.vendorName == userVendorName) || (laptop.vendorCountry == userVendorCountry) ||
                    (laptop.screenSize == userScreenSize) || (laptop.laptopRAM == userLaptopRAM) || (laptop.laptopPrice == userLaptopPrice))
                {
                    laptop.PrintLaptopInfo();
                }
                else
                {
                    Console.WriteLine("No matches in shop!");
                }
            }
        }

    }

}
